# -*- coding: utf-8 -*-
#----------------------------------------------------------------------------
# File: $Id: jasmine_book.py 26 2007-12-30 08:44:27Z mingli.yuan $
# Revision: $Revision: 26 $
#----------------------------------------------------------------------------
# py-jasmine: A python GUI tool for pdf journal making
# Copyright (C) 2007  Mingli Yuan
#
# This program is a part of py-jasmine.
#
# py-jasmine is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# py-jasmine is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with py-jasmine. If not, see <http://www.gnu.org/licenses/>.
#
# This software consists of voluntary contributions made by many
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://py-jasmine.googlecode.com/svn/trunk/.
#
#----------------------------------------------------------------------------

"""the main operational notebook for py-jasmine
@version: $Id: jasmine_book.py 26 2007-12-30 08:44:27Z mingli.yuan $
@author: Mingli Yuan <me@mingli-yuan.info>
@license: gpl
"""

__version__ = "$Revision: 26 $"


import os.path
import wx
import  wx.xrc  as  xrc


class JasmineBook(wx.Notebook):
    """The base class for operational notebook for py-jasmine application."""

    def __init__(self, parent, id=-1, model=None):
        wx.Notebook.__init__(self, parent, id, style=wx.BK_LEFT)
        self.model = model
        self.LoadPages()
        parent.SendSizeEvent()

    def MakePanel(self, name):
        lower_name = name.lower()
        renders = self.model.get("renders")
        if(renders.has_key(lower_name)):
            render_file = os.path.join(self.model.base_path, renders[lower_name])
            res = xrc.XmlResource(render_file)
            panel = res.LoadPanel(self, name)
        else:
            panel = wx.Panel(self, -1)
        return panel

    def LoadPages(self):
        #NOOP
        return

    def Close(self):
        parent = self.GetParent()
        parent.RemoveChild(self)
        parent.Update()
        self.Destroy()


class JasmineIssueBook(JasmineBook):
    """The notebook for issue operation.."""

    def __init__(self, parent, id=-1, model=None):
        JasmineBook.__init__(self, parent, id, model)

    def LoadPages(self):
        win = self.MakePanel()
        self.AddPage(win, "Issue")
        win = self.MakePanel()
        self.AddPage(win, "Articles")
        win = self.MakePanel()
        self.AddPage(win, "Photos")
        win = self.MakePanel()
        self.AddPage(win, "Makeup")


class JasmineTemplateBook(JasmineBook):
    """The notebook for template operation."""

    def __init__(self, parent, id=-1, model=None):
        JasmineBook.__init__(self, parent, id, model)

    def LoadPages(self):
        win = self.MakePanel("meta.global")
        self.AddPage(win, "Global")
        win = self.MakePanel("meta.issue")
        self.AddPage(win, "Issue")
        win = self.MakePanel("meta.columns")
        self.AddPage(win, "Columns")
        win = self.MakePanel("meta.resources")
        self.AddPage(win, "Resources")

